package org.tobuy.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.tobuy.vo.*;
import org.tobuy.factory.*;

public class AdminDelete extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String path = "adminDelete_pass.jsp";
		String id = (String)request.getParameter("id");
		String type = (String)request.getParameter("type");
		String info = "Delete failed!";
		if(type.equals("user")){
			User user = new User();
			try {
				user = UserDAOFactory.getIUserDAOInstance().findUser(id);
				UserDAOFactory.getIUserDAOInstance().deleteUser(user);
			} catch (Exception e) {
				e.printStackTrace();
			}
			info ="User deleted!";
		}
		if(type.equals("item")){
			Item item = new Item();
			try {
				ItemDAOFactory.getIItemDAOInstance().deleteItem(id);
			} catch (Exception e) {
				e.printStackTrace();
			}
			info ="Item deleted!";
		}
		request.setAttribute("info", info);
		request.getRequestDispatcher(path).forward(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doGet(request, response);
	}

}
